//
//  BuycartTableViewCell.m
//  cityStar
//
//  Created by Hancong on 14/12/22.
//  Copyright (c) 2014年 tiny. All rights reserved.
//

#import "BuycartTableViewCell.h"
#import "UIImageView+WebCache.h"

@implementation BuycartTableViewCell

+(CGFloat)heightOfTableCell
{
    return 106;
}

- (void)awakeFromNib {
    // Initialization code
}

-(void)configWithselect:(BOOL)state andGoodCart:(BuycartGood *)cartGood andindex:(NSIndexPath *)index
{
    self.index = index;
    [self.imageCommodity sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.icszx.com/image/c/id/%@/w/150/h/130/m/0",cartGood.images]] placeholderImage:[UIImage imageNamed:@"购物车列表_img"]];
    self.labelContent.text = [NSString stringWithFormat:@"%@",cartGood.goods_name];
    self.labelNewPrice.text = [NSString stringWithFormat:@"￥%@",cartGood.price];
//    self.labelOldPrice.text = cartGood.market_price;
    self.labelNumber.text = [NSString stringWithFormat:@"x%@",cartGood.number];
    NSString *oldPrice = [NSString stringWithFormat:@"￥%@",cartGood.market_price];
    NSUInteger length = [oldPrice length];
    
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:oldPrice];
    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, length)];
    [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, length)];
    [self.labelOldPrice setAttributedText:attri];
    
    if (state == YES) {
        self.btnSelect.selected = YES;
    }else{
        self.btnSelect.selected = NO;
    }
}

-(IBAction)changeNumOfCommidity:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(commodityChangeNumberWithIndex:)] == YES) {
        [self.delegate commodityChangeNumberWithIndex:self.index];
    }
}

-(IBAction)btnselect_Touch:(UIButton *)sender
{
    if (self.btnSelect.selected == YES) {
        if ([self.delegate respondsToSelector:@selector(buycartTableViewCellTouchSeleceButtonWithIndex:andisslelect:)]) {
            [self.delegate buycartTableViewCellTouchSeleceButtonWithIndex:self.index andisslelect:NO];
        }
    }else{
        if ([self.delegate respondsToSelector:@selector(buycartTableViewCellTouchSeleceButtonWithIndex:andisslelect:)]) {
            [self.delegate buycartTableViewCellTouchSeleceButtonWithIndex:self.index andisslelect:YES];
        }
    }
    self.btnSelect.selected = !sender.selected;


//    self.btnSelect.selected = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
